#include <QtGui>
#include <QTranslator>
#include <QtCore/QTextCodec>
#include "gv_systemtransmitterssetupdialog.h"
#include "gv_systemtransmittersconfigurationdialog.h"
#include "gv_home.h"
#include "gv_setting.h"

extern GV_Setting *gvsetting;
extern QDialog  *dialog;
GV_SystemTransmittersSetupDialog::GV_SystemTransmittersSetupDialog(QWidget *parent)
       : QDialog(parent)
{
    setupUi(this);

    QTranslator translator;
    translator.load(gvsetting->GV_GetLanguage(),".");
    qApp->installTranslator(&translator);
    reloadtext();

    //AlarmButton->hide();
    AnalogueCurrent4mA=0;
    AnalogueCurrent20mA=0;
    AnalogueCurrentButtonStatus=0;//4mA
    AnalogueCurrenLabel->setText(QString::number(0));

    AlarmCurrent1e=0;
    AlarmCurrent2e=0;
    AlarmCurrent3e=0;
    AlarmCurrentButtonStatus=0;//4mA
    AlarmCurrentLabel->setText(QString::number(0));

    LinearoffsetValue = 0;
    LinearoffsetCurrentLabel->setText(QString::number(0));

    SamplingtimeValue = 0;
    SamplingtimeTimeLabel->setText(QString::number(0));

    TimeHintsLabel->setText((QDateTime::currentDateTime().toString("hh:mm:ss")));
    DateHintsLabel->setText((QDateTime::currentDateTime().toString("yyyy-MM-dd")));
    analogueclicked();
    timer = new QTimer;
    connect(timer,SIGNAL(timeout()),this,SLOT(GV_chTime()));
    connect(CopyButton,SIGNAL(clicked()),this,SLOT(home()));
    connect(CancelButton,SIGNAL(clicked()),this,SLOT(home()));
    connect(BackButton,SIGNAL(clicked()),this,SLOT(home()));

    connect(AnalogueButton,SIGNAL(clicked()),this,SLOT(analogueclicked()));
    connect(AlarmButton,SIGNAL(clicked()),this,SLOT(alarmclicked()));
    connect(LinearoffsetButton,SIGNAL(clicked()),this,SLOT(linearoffsetclicked()));
    connect(SamplingtimeButton,SIGNAL(clicked()),this,SLOT(samplingtimeclicked()));
    connect(DetailedviewButton,SIGNAL(clicked()),this,SLOT(detailedviewclicked()));

    connect(AnalogueCurrent4mAButton,SIGNAL(clicked()),this,SLOT(AnalogueCurrent4mAButtonClicked()));
    connect(AnalogueCurrent20mAButton,SIGNAL(clicked()),this,SLOT(AnalogueCurrent20mAButtonClicked()));
    connect(AnalogueCurrentDecreaseButton,SIGNAL(clicked()),this,SLOT(AnalogueCurrentDecreaseButtonClicked()));
    connect(AnalogueCurrentIncreaseButton,SIGNAL(clicked()),this,SLOT(AnalogueCurrentIncreaseButtonClicked()));

    connect(AlarmCurrent1eButton,SIGNAL(clicked()),this,SLOT(AlarmCurrent1eButtonClicked()));
    connect(AlarmCurrent2eButton,SIGNAL(clicked()),this,SLOT(AlarmCurrent2eButtonClicked()));
    connect(AlarmCurrent3eButton,SIGNAL(clicked()),this,SLOT(AlarmCurrent3eButtonClicked()));
    connect(AlarmCurrentDecreaseButton,SIGNAL(clicked()),this,SLOT(AlarmCurrentDecreaseButtonClicked()));
    connect(AlarmCurrentIncreaseButton,SIGNAL(clicked()),this,SLOT(AlarmCurrentIncreaseButtonClicked()));

    connect(LinearoffsetCurrentDecreaseButton,SIGNAL(clicked()),this,SLOT(LinearoffsetCurrentDecreaseButtonClicked()));
    connect(LinearoffsetCurrentIncreaseButton,SIGNAL(clicked()),this,SLOT(LinearoffsetCurrentIncreaseButtonClicked()));

    connect(SamplingtimeTimeDecreaseButton,SIGNAL(clicked()),this,SLOT(SamplingtimeTimeDecreaseButtonClicked()));
    connect(SamplingtimeTimeIncreaseButton,SIGNAL(clicked()),this,SLOT(SamplingtimeTimeIncreaseButtonClicked()));

    timer->start(1000);
}
void GV_SystemTransmittersSetupDialog::reloadtext()
{
    //NameHintsLabel->setText(tr("Zones"));
}
void GV_SystemTransmittersSetupDialog::GV_chTime()
{
    TimeHintsLabel->setText((QDateTime::currentDateTime().toString("hh:mm:ss")));
    DateHintsLabel->setText((QDateTime::currentDateTime().toString("yyyy-MM-dd")));
}

void GV_SystemTransmittersSetupDialog::home()
{
    QDialog *dialog1 = new GV_SystemTransmittersConfigurationDialog;
    dialog1->show();
    delete dialog;
    dialog = dialog1;
}
void GV_SystemTransmittersSetupDialog::analogueclicked()
{
    AnalogueFrame->show();
    AlarmFrame->hide();
    LinearoffsetFrame->hide();
    SamplingtimeFrame->hide();
    DetailedviewFrame->hide();

    AnalogueFrame->setGeometry(QRect(20,70,300,200));
}
void GV_SystemTransmittersSetupDialog::alarmclicked()
{
    AnalogueFrame->hide();
    AlarmFrame->show();
    LinearoffsetFrame->hide();
    SamplingtimeFrame->hide();
    DetailedviewFrame->hide();

    AlarmFrame->setGeometry(QRect(20,70,300,200));
}
void GV_SystemTransmittersSetupDialog::linearoffsetclicked()
{
    AnalogueFrame->hide();
    AlarmFrame->hide();
    LinearoffsetFrame->show();
    SamplingtimeFrame->hide();
    DetailedviewFrame->hide();

    LinearoffsetFrame->setGeometry(QRect(20,70,300,200));
}
void GV_SystemTransmittersSetupDialog::samplingtimeclicked()
{
    AnalogueFrame->hide();
    AlarmFrame->hide();
    LinearoffsetFrame->hide();
    SamplingtimeFrame->show();
    DetailedviewFrame->hide();

    SamplingtimeFrame->setGeometry(QRect(20,70,300,200));
}
void GV_SystemTransmittersSetupDialog::detailedviewclicked()
{
    AnalogueFrame->hide();
    AlarmFrame->hide();
    LinearoffsetFrame->hide();
    SamplingtimeFrame->hide();
    DetailedviewFrame->show();

    DetailedviewFrame->setGeometry(QRect(20,70,300,200));
#if 1
    AnalogueDetailed4mA->setText("4mA@" + QString::number(AnalogueCurrent4mA) +"PPM");
    AnalogueDetailed20mA->setText("4mA@" + QString::number(AnalogueCurrent20mA) +"PPM");
    Alarm1eDetailed->setText("1e Alarm@" + QString::number(AlarmCurrent1e) +"PPM");
    Alarm2eDetailed->setText("2e Alarm@" + QString::number(AlarmCurrent2e) +"PPM");
    Alarm3eDetailed->setText("3e Alarm@" + QString::number(AlarmCurrent3e) +"PPM");
    LinearoffsetDetailed->setText(QString::number(LinearoffsetValue) +"PPM");
    SamplingtimeDetailed->setText(QString::number(SamplingtimeValue) +"Minutes");
#endif
}

void GV_SystemTransmittersSetupDialog:: AnalogueCurrent4mAButtonClicked()
{
    AnalogueCurrenLabel->setText(QString::number(AnalogueCurrent4mA));
    AnalogueCurrentButtonStatus=0;
}
void GV_SystemTransmittersSetupDialog:: AnalogueCurrent20mAButtonClicked()
{
    AnalogueCurrenLabel->setText(QString::number(AnalogueCurrent20mA));
    AnalogueCurrentButtonStatus=1;
}
void GV_SystemTransmittersSetupDialog:: AnalogueCurrentDecreaseButtonClicked()
{
    if(AnalogueCurrentButtonStatus==0){//4mA
        AnalogueCurrent4mA--;
        AnalogueCurrenLabel->setText(QString::number(AnalogueCurrent4mA));
    }else if(AnalogueCurrentButtonStatus==1){//20mA
        AnalogueCurrent20mA--;
        AnalogueCurrenLabel->setText(QString::number(AnalogueCurrent20mA));
    }

}
void GV_SystemTransmittersSetupDialog:: AnalogueCurrentIncreaseButtonClicked()
{
    if(AnalogueCurrentButtonStatus==0){//4mA
        AnalogueCurrent4mA++;
        AnalogueCurrenLabel->setText(QString::number(AnalogueCurrent4mA));
    }else if(AnalogueCurrentButtonStatus==1){//20mA
        AnalogueCurrent20mA++;
        AnalogueCurrenLabel->setText(QString::number(AnalogueCurrent20mA));
    }
}


void GV_SystemTransmittersSetupDialog:: AlarmCurrent1eButtonClicked()
{
    AlarmCurrentLabel->setText(QString::number(AlarmCurrent1e));
    AlarmCurrentButtonStatus=0;
}
void GV_SystemTransmittersSetupDialog:: AlarmCurrent2eButtonClicked()
{
    AlarmCurrentLabel->setText(QString::number(AlarmCurrent2e));
    AlarmCurrentButtonStatus=1;
}
void GV_SystemTransmittersSetupDialog:: AlarmCurrent3eButtonClicked()
{
    AlarmCurrentLabel->setText(QString::number(AlarmCurrent3e));
    AlarmCurrentButtonStatus=2;
}
void GV_SystemTransmittersSetupDialog:: AlarmCurrentDecreaseButtonClicked()
{
    if(AlarmCurrentButtonStatus==0){//4mA
        AlarmCurrent1e--;
        AlarmCurrentLabel->setText(QString::number(AlarmCurrent1e));
    }else if(AlarmCurrentButtonStatus==1){//20mA
        AlarmCurrent2e--;
        AlarmCurrentLabel->setText(QString::number(AlarmCurrent2e));
    }
    else if(AlarmCurrentButtonStatus==2){//20mA
            AlarmCurrent3e--;
            AlarmCurrentLabel->setText(QString::number(AlarmCurrent3e));
    }
}

void GV_SystemTransmittersSetupDialog:: AlarmCurrentIncreaseButtonClicked()
{
    if(AlarmCurrentButtonStatus==0){//4mA
        AlarmCurrent1e++;
        AlarmCurrentLabel->setText(QString::number(AlarmCurrent1e));
    }else if(AlarmCurrentButtonStatus==1){//20mA
        AlarmCurrent2e++;
        AlarmCurrentLabel->setText(QString::number(AlarmCurrent2e));
    }else if(AlarmCurrentButtonStatus==2){//20mA
        AlarmCurrent3e++;
        AlarmCurrentLabel->setText(QString::number(AlarmCurrent3e));
    }
}

void GV_SystemTransmittersSetupDialog:: LinearoffsetCurrentDecreaseButtonClicked()
{    
    LinearoffsetValue--;
    LinearoffsetCurrentLabel->setText(QString::number(LinearoffsetValue));
}
void GV_SystemTransmittersSetupDialog:: LinearoffsetCurrentIncreaseButtonClicked()
{
    LinearoffsetValue++;
    LinearoffsetCurrentLabel->setText(QString::number(LinearoffsetValue));
}


void GV_SystemTransmittersSetupDialog:: SamplingtimeTimeDecreaseButtonClicked()
{
    SamplingtimeValue--;
    SamplingtimeTimeLabel->setText(QString::number(SamplingtimeValue));
}
void GV_SystemTransmittersSetupDialog:: SamplingtimeTimeIncreaseButtonClicked()
{
    SamplingtimeValue++;
    SamplingtimeTimeLabel->setText(QString::number(SamplingtimeValue));
}
